<?php session_start();
include("3.php");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="es" lang="es">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="keywords" content="php, codigo fuente, codigo escrito, descarga gratis, AJAX, javascript, MySQL, scripts, rincondelcodigo, google maps" />
<meta name="ROBOTS" content="NOARCHIVE" />
<title>mapas google</title>
<!--www.rincondelcodigo.com-->
<script src="http://maps.google.com/maps?file=api&v=2&key=ABQIAAAAaOuNwQpl_6SNrN9SPqlprhQmVl4M6pUqpH8m1u86xCFJGE2ovxS4R4LhSaw6omab-H9GhhvM5WdLMw" type="text/javascript"></script>
<script> function boton() {location="2.php"}
function boton2() {location="7.php"}
 </script>
</head>
<body onload="initialize()" onunload="GUnload()" id="home">
<?php 
$registros=mysql_query("select * from google_maps where Nick='$_SESSION[estado]'", $conexion) or die("Problemas en el select:".mysql_error());
if ($reg=mysql_fetch_array($registros))
{ if (($reg['Lat']=="0") && ($reg['Lng']=="0")) { ?>
Todavia no te has geolocalizado? <form><input type="button" value="Geolocalzate" class="button" onClick="boton()"></form>
<?php } if (($reg['Lat']!="0") && ($reg['Lng']!="0")) {
echo "Latitud: ".$reg['Lat']."<br>Longitud: ".$reg['Lng']; } ?>
<br><br>Si el usuario quiere cambiar la localizacion lo puede hacer
<form>
<input type="button" value="Cambiar localizacin" class="button" onClick="boton()"><br><br>
Aqui se puede ver el mapa completo de usuarios geolocalizados<br> 
<input type="button" value="Ver mapa completo" class="button" onClick="boton2()"><br><br> 
</form>
   <div id="map" style="width: 300px; height: 200px;"></div>
    <script type="text/javascript">
    if (GBrowserIsCompatible()) {
      var side_bar_html = "";
      var gmarkers = [];
      var htmls = [];
      var i = 0;
      var gicons = [];
      gicons["map"] = new GIcon(G_DEFAULT_ICON, "http://maps.google.com/mapfiles/ms/micons/red-pushpin.png");
      function createMarker(point,name,html,icontype) {
        var marker = new GMarker(point, gicons[icontype]);
        GEvent.addListener(marker, "click", function() {
          marker.openInfoWindowHtml(html);
        });
        gmarkers[i] = marker;
        htmls[i] = html;
        side_bar_html += '<a href="javascript:myclick(' + i + ')">' + name + '<\/a><br>';
        i++;
        return marker;
      }
      function myclick(i) {
        gmarkers[i].openInfoWindowHtml(htmls[i]);
      }
      var map = new GMap2(document.getElementById("map"));
     <?php 
$nick=$_SESSION['estado'];
$registros=mysql_query("select * from google_maps where Nick='$nick'", $conexion) or die("Problemas en el select:".mysql_error());
if ($reg=mysql_fetch_array($registros))
{ 
echo "map.setCenter(new GLatLng(" . $reg['Lat'] . "," . $reg['Lng'] . "), 5)";  } ?>

      var request = GXmlHttp.create();
      request.open("GET", "6.php", true);
      request.onreadystatechange = function() {
        if (request.readyState == 4) {
          var xmlDoc = GXml.parse(request.responseText);
          var markers = xmlDoc.documentElement.getElementsByTagName("marker");
           for (var i = 0; i < markers.length; i++) {
            var lat = parseFloat(markers[i].getAttribute("lat"));
            var lng = parseFloat(markers[i].getAttribute("lng"));
            var point = new GLatLng(lat,lng);
            var html = markers[i].getAttribute("html");
            var label = markers[i].getAttribute("label");
            var icontype = markers[i].getAttribute("icontype");
            var marker = createMarker(point,label,html,icontype);
            map.addOverlay(marker);
          }
          document.getElementById("side_bar").innerHTML = side_bar_html;
        }
      }
      request.send(null);
    }
    else {
      alert("El API de google maps no es compatible con este browser");
    }
    </script>
<?php } ?>
</html>
